/*
 * @Author: 刘润泽
 * @Date: 2023-02-22 19:39:56
 * @LastEditors: 刘润泽
 * @LastEditTime: 2023-03-14 16:51:37
 * @Description: 
 */
package server;

import com.alibaba.fastjson.JSON;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;

import server.business.pojo.State;
import server.business.service.StateService;
import server.main.config.springsecurity.config.CustomerFilterInvocationSecurityMetadataSource;
import server.main.mapper.PermissionMapper;
import server.main.pojo.Permission;
import java.util.List;

/**
 * @auther MingHsZzz
 * @Date 2022/10/26 14:01
 * @project main
 * @description
 */
public class test {
    @Autowired
    PermissionMapper permissionMapper;

    @Autowired
    private StateService stateService;

    public List<Permission> getpermission() {
        List<Permission> allPermission = null; // 数据库中所有的资源信息

        allPermission = permissionMapper.getAllpermission();
        // 需要将每个permission和role绑起来
        for (Permission permission : allPermission) {
            permission.setRoles(permissionMapper.getRoles(permission.getId()));
        }
        System.out.println("<-----allPermission----->" + JSON.toJSONString(allPermission));
        return allPermission;
    }

    public void testpermission(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(MainApplication.class, args);
        String[] names = run.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }
        CustomerFilterInvocationSecurityMetadataSource customerFilterInvocationSecurityMetadataSource = run
                .getBean(CustomerFilterInvocationSecurityMetadataSource.class);
        System.out.println(customerFilterInvocationSecurityMetadataSource.getAllPermission());

        customerFilterInvocationSecurityMetadataSource.setAllPermission(getpermission());

        System.out.println(customerFilterInvocationSecurityMetadataSource.getAllPermission());

    }

    @Test
    public void main() {
        System.out.println(stateService);
        List<State> stateList = stateService.list();
        System.out.println(stateList);

    }

}
